package com.lwp.lambda;

import static org.junit.Assert.fail;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;import java.util.stream.Collector;
import java.util.stream.Collectors;
import java.util.stream.Stream;

import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;

public class ListObjectTest2 extends BaseTest {

	private static List<String> list = new ArrayList<>();
	private static List<Integer> intList = new ArrayList<>();
	private static List<Person> personList = new ArrayList<>();

	@BeforeClass
	public static void setUpBeforeClass() throws Exception {
	}

	@AfterClass
	public static void tearDownAfterClass() throws Exception {
	}

	@Before
	public void setUp() throws Exception {
		System.out.println("local .. before");
	}

	@After
	public void tearDown() throws Exception {
		System.out.println("local .. after");
	}

	@Test
	public void test() {
		fail("Not yet implemented");
	}

	@Test
	public void testForeach() {
		//第一种
		list.forEach(t -> {
			System.out.println(t);
		});
		//第二种
		list.forEach(t -> System.out.println(t));
	}
	/**
	 * 截取list长度 从0开始
	 */
	@Test
	public void testLimit() {
		//第一种
		int maxSize = 3;//0从0开始截取 超过就获取全部元素 必须大于-1否则抛出异常
		System.out.println(list.stream().limit(maxSize).collect(Collectors.toList()));
		//第二种
		System.out.println(list.parallelStream().limit(maxSize).collect(Collectors.toList()));
	}

}
